import Vue from 'vue'
import Router from 'vue-router'
import Main from '../views/Main'
import GiftEdit from '../views/GiftEdit'
import GiftList from '../views/GiftList'
import CategoryEdit from '../views/CategoryEdit'
import CategoryList from '../views/CategoryList' 
import ArticleEdit from '../views/ArticleEdit'
import ArticleList from '../views/ArticleList'
import AdvertisementEdit from '../views/AdvertisementEdit'
import AdvertisementList from '../views/AdvertisementList'
import AdminUserEdit from '../views/AdminUserEdit'
import AdminUserList from '../views/AdminUserList'
import FindPersonEdit from '../views/FindPersonEdit'
import FindPersonList from '../views/FindPersonList'
import ProjectEdit from '../views/ProjectEdit'
import ProjectList from '../views/ProjectList'
import ActivityEdit from '../views/ActivityEdit'
import ActivityList from '../views/ActivityList'
import ForumEdit from '../views/ForumEdit'
import ForumList from '../views/ForumList'
import MixEdit from '../views/MixEdit'
import MixList from '../views/MixList'
import Login from '../views/Login'
Vue.use(Router)

const router =  new Router({
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login,
      meta:{isPublic:true}
    },
     {
      path: '/',
      name: 'main',
      component: Main,
      children:[

        // 分类
        {path:'/categories/create',component:CategoryEdit},
        {path:'/categories/edit/:id',component:CategoryEdit,props:true},
        {path:'/categories/list',component:CategoryList},

        // 奖品
        {path:'/gifts/create',component:GiftEdit},
        {path:'/gifts/edit/:id',component:GiftEdit,props:true},
        {path:'/gifts/list',component:GiftList},
        // 活动
        {path:'/activity/create',component:ActivityEdit},
        {path:'/activity/edit/:id',component:ActivityEdit,props:true},
        {path:'/activity/list',component:ActivityList},
         // 项目
         {path:'/project/create',component:ProjectEdit},
         {path:'/project/edit/:id',component:ProjectEdit,props:true},
         {path:'/project/list',component:ProjectList},
        
        //寻人FindPeople
        {path:'/findPerson/create',component:FindPersonEdit},
        {path:'/findPerson/edit/:id',component:FindPersonEdit,props:true},
        {path:'/findPerson/list',component:FindPersonList},

         
        // 文章
        {path:'/articles/create',component:ArticleEdit},
        {path:'/articles/edit/:id',component:ArticleEdit,props:true},
        {path:'/articles/list',component:ArticleList},
        // 广告
        {path:'/advertisement/create',component:AdvertisementEdit},
        {path:'/advertisement/edit/:id',component:AdvertisementEdit,props:true},
        {path:'/advertisement/list',component:AdvertisementList},

        // 管理员
        {path:'/adminUser/create',component:AdminUserEdit},
        {path:'/adminUser/edit/:id',component:AdminUserEdit,props:true},
        {path:'/adminUser/list',component:AdminUserList},
        // 论坛
        {path:'/forum/create',component:ForumEdit},
        {path:'/forum/edit/:id',component:ForumEdit,props:true},
        {path:'/forum/list',component:ForumList},

          // 混合
          {path:'/mix/create',component:MixEdit},
          {path:'/mix/edit/:id',component:MixEdit,props:true},
          {path:'/mix/list',component:MixList},
      ]
    }
  ]
})

router.beforeEach((to,from,next)=>{
  if( !to.meta.isPublic && !sessionStorage.token){
    return next('/login')
  }
  // console.log(to,from,next);
  next()
})

export default router